<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="订单ID" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="用户ID" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收件人姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入收件人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收件人电话" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入收件人电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品ID" prop="pid">
        <el-input
          v-model="queryParams.pid"
          placeholder="请输入商品ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入商品"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="快递单号" prop="deliveryId">
        <el-input
          v-model="queryParams.deliveryId"
          placeholder="请输入快递单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="shipmentStatus">
        <el-select
          v-model="queryParams.shipmentStatus"
          placeholder="请选择订单状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="分类" prop="status">
        <el-select v-model="queryParams.category" placeholder="请选择分类" clearable size="small">
          <el-option label="请选择字典生成" 
            v-for="item in categoryOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="支付方式" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式" clearable size="small">
          <el-option label="请选择字典生成" 
            v-for="item in payTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="支付时间" prop="createTime">
        <el-date-picker
          v-model="payTime"
          :picker-options="pickerOptions"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="支付时间" prop="createTime">
        <DatePicker v-model="cTime" :timevalue1="cTime"></DatePicker>
      </el-form-item>
      <el-form-item style="display: block">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ds:productOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ds:productOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ds:productOrder:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ds:productOrder:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="productOrderList"
      @selection-change="handleSelectionChange"
      border
    >
      <el-table-column type="selection" width="55" fixed align="center" />
      <el-table-column
        label="订单ID"
        align="center"
        fixed
        prop="id"
        width="80"
      />
      <el-table-column
        label="用户ID"
        align="center"
        fixed
        prop="uid"
        width="100"
      />
      <el-table-column
        label="订单号"
        align="center"
        prop="orderId"
        fixed
        width="180"
      />
      <el-table-column
        label="收件人"
        align="center"
        prop="realName"
        width="100"
      />
      <el-table-column
        label="收件人电话"
        align="center"
        prop="userPhone"
        width="120"
      />
      <el-table-column
        label="收件人地址"
        align="center"
        prop="userAddress"
        min-width="220"
      />
      <el-table-column
        label="商品ID"
        align="center"
        prop="pid"
        min-width="100"
      />
      <el-table-column
        label="商品"
        align="center"
        prop="productName"
        min-width="200"
      />
      <el-table-column
        label="购买数量"
        align="center"
        prop="totalNum"
        width="80"
      />
      <el-table-column
        label="总价"
        align="center"
        prop="totalPrice"
        width="80"
      />
      <el-table-column
        label="订单状态"
        align="center"
        prop="shipmentStatus"
        width="80"
      >
        <template slot-scope="scope">
          <!-- <span v-if="scope.row.shipmentStatus == 0">未发货</span>
          <span v-if="scope.row.shipmentStatus == 1">待收货</span>
          <span v-if="scope.row.shipmentStatus == 2">已收货</span> -->
          <span>{{ parseOrderState(scope.row) }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="支付渠道"
        align="center"
        prop="shipmentStatus"
        width="120"
      >
        <template slot-scope="scope">
          <span>{{ parseOrderPayWay(scope.row) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="快递公司"
        width="100"
        align="center"
        prop="deliveryNumber"
      >
        <template slot-scope="scope">
          <span>{{ parseExpressCompony(scope.row) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="快递单号"
        width="160"
        align="center"
        prop="deliveryId"
      />
      <el-table-column
        label="备注"
        min-width="200"
        align="center"
        prop="remark"
      />
      <el-table-column
        label="支付时间"
        width="140"
        align="center"
        prop="createTime"
      />

      <!--
      <el-table-column label="实际支付金额" align="center" prop="payPrice" />

      <el-table-column label="详细地址" align="center" prop="userAddress" />
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payType" />
      <el-table-column label="快递名称" align="center" prop="deliveryName" />
      <el-table-column label="发货类型" align="center" prop="deliveryType" />
      <el-table-column label="快递单号" align="center" prop="deliveryId" />
      <el-table-column label="商品id" align="center" prop="pid" />
      <el-table-column label="运费金额" align="center" prop="freightPrice" />
      <el-table-column label="订单号" align="center" prop="orderId" />
      <el-table-column label="邮费" align="center" prop="totalPostage" />
      <el-table-column label="支付邮费" align="center" prop="payPostage" />
      <el-table-column label="抵扣金额" align="center" prop="deductionPrice" />
      <el-table-column label="退款状态" align="center" prop="refundStatus" />
      <el-table-column label="退款时间" align="center" prop="refundReasonTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refundReasonTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="前台退款原因" align="center" prop="refundReasonWap" />
      <el-table-column label="不退款的理由" align="center" prop="refundReason" />
      <el-table-column label="退款金额" align="center" prop="refundPrice" />
      <el-table-column label="是否删除" align="center" prop="isDel" />
      <el-table-column label="成本价" align="center" prop="cost" />
      <el-table-column label="配送方式" align="center" prop="shippingType" />
      <el-table-column label="支付渠道" align="center" prop="channel" />
      <el-table-column label="后台是否删除" align="center" prop="isSystemDel" />
      -->
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
        min-width="100"
      >
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ds:productOrder:edit']"
            >发货</el-button
          >
          <!-- <el-button
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ds:productOrder:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="uid">
          <el-input
            disabled="disabled"
            v-model="form.uid"
            placeholder="请输入用户id"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="realName">
          <el-input
            disabled="disabled"
            v-model="form.realName"
            placeholder="请输入姓名"
          />
        </el-form-item>
        <el-form-item label="用户电话" prop="userPhone">
          <el-input
            disabled="disabled"
            v-model="form.userPhone"
            placeholder="请输入用户电话"
          />
        </el-form-item>
        <el-form-item label="详细地址" prop="userAddress">
          <el-input
            disabled="disabled"
            v-model="form.userAddress"
            placeholder="请输入详细地址"
          />
        </el-form-item>
        <el-form-item label="商品id" prop="pid">
          <el-input
            disabled="disabled"
            v-model="form.pid"
            placeholder="请输入商品id"
          />
        </el-form-item>
        <el-form-item label="商品" prop="productName">
          <el-input
            disabled="disabled"
            v-model="form.productName"
            placeholder="请输入商品"
          />
        </el-form-item>
        <el-form-item label="购买数量" prop="totalNum">
          <el-input
            disabled="disabled"
            v-model="form.totalNum"
            placeholder="请输入购买数量"
          />
        </el-form-item>
        <el-form-item label="订单编号" prop="totalPrice">
          <el-input
            disabled="disabled"
            v-model="form.totalPrice"
            placeholder="请输入订单总价"
          />
        </el-form-item>
        <el-form-item label="订单号" prop="totalPrice">
          <el-input
            disabled="disabled"
            v-model="form.orderId"
            placeholder="订单号"
          />
        </el-form-item>
        <!--
		<el-form-item label="订单号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单号" />
        </el-form-item>
		<el-form-item label="运费金额" prop="freightPrice">
          <el-input v-model="form.freightPrice" placeholder="请输入运费金额" />
        </el-form-item>
		<el-form-item label="邮费" prop="totalPostage">
          <el-input v-model="form.totalPostage" placeholder="请输入邮费" />
        </el-form-item>
        <el-form-item label="实际支付金额" prop="payPrice">
          <el-input v-model="form.payPrice" placeholder="请输入实际支付金额" />
        </el-form-item>
		<el-form-item label="支付邮费" prop="payPostage">
          <el-input v-model="form.payPostage" placeholder="请输入支付邮费" />
        </el-form-item>
        <el-form-item label="抵扣金额" prop="deductionPrice">
          <el-input v-model="form.deductionPrice" placeholder="请输入抵扣金额" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable size="small"
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
          <el-select v-model="form.payType" placeholder="请选择支付方式">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
		<el-form-item label="退款状态">
          <el-radio-group v-model="form.refundStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="退款时间" prop="refundReasonTime">
          <el-date-picker clearable size="small"
            v-model="form.refundReasonTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择退款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="前台退款原因" prop="refundReasonWap">
          <el-input v-model="form.refundReasonWap" placeholder="请输入前台退款原因" />
        </el-form-item>
        <el-form-item label="不退款的理由" prop="refundReason">
          <el-input v-model="form.refundReason" placeholder="请输入不退款的理由" />
        </el-form-item>
        <el-form-item label="退款金额" prop="refundPrice">
          <el-input v-model="form.refundPrice" placeholder="请输入退款金额" />
        </el-form-item>
		<el-form-item label="快递名称" prop="deliveryName">
          <el-input v-model="form.deliveryName" placeholder="请输入快递名称" />
        </el-form-item>
        <el-form-item label="发货类型" prop="deliveryType">
          <el-select v-model="form.deliveryType" placeholder="请选择发货类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="快递单号" prop="deliveryId">
          <el-input v-model="form.deliveryId" placeholder="请输入快递单号" />
        </el-form-item>
        <el-form-item label="是否删除" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入是否删除" />
        </el-form-item>
        <el-form-item label="成本价" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入成本价" />
        </el-form-item>
        <el-form-item label="配送方式" prop="shippingType">
          <el-select v-model="form.shippingType" placeholder="请选择配送方式">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付渠道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入支付渠道" />
        </el-form-item>
        <el-form-item label="后台是否删除" prop="isSystemDel">
          <el-input v-model="form.isSystemDel" placeholder="请输入后台是否删除" />
        </el-form-item>
		-->
        <el-form-item label="快递单号" prop="deliveryId">
          <el-input v-model="form.deliveryId" placeholder="请输入快递单号" />
        </el-form-item>
        <el-form-item label="快递公司" prop="deliveryNumber">
          <el-select
            v-model="form.deliveryNumber"
            placeholder="请选择快递公司"
            clearable
          >
            <el-option
              v-for="item in companyOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态" prop="shipmentStatus">
          <el-radio-group v-model="form.shipmentStatus">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProductOrder,
  getProductOrder,
  delProductOrder,
  addProductOrder,
  updateProductOrder,
  exportProductOrder,
} from "@/api/ds/productOrder";
import { addAchievement, chargeback } from "@/api/ds/orderManage";
import delivery from "@/utils/delivery";
import DatePicker from "@/components/DatePicker";

import expressJson from "@/utils/express.json";

export default {
  name: "ProductOrder",
  components: { DatePicker },
  data() {
    var validateID = (rule, value, callback) => {
      if (value) {
        if (!/^[0-9]*[1-9][0-9]*$/.test(value)) {
          callback(new Error("请输入正确的值"));
        } else {
          callback();
        }
      } else {
        callback(new Error("请输入值"));
      }
    };

    return {
      // 遮罩层
      loading: true,
      pickerOptions: {
        // 设置不能选择的日期
        onPick: ({ maxDate, minDate }) => {
          this.choiceDate0 = minDate.getTime();
          if (maxDate) {
            this.choiceDate0 = "";
          }
        },
        disabledDate: (time) => {
          let choiceDateTime = new Date(this.choiceDate0).getTime();
          const minTime = new Date(choiceDateTime).setMonth(
            new Date(choiceDateTime).getMonth() - 1
          );
          const maxTime = new Date(choiceDateTime).setMonth(
            new Date(choiceDateTime).getMonth() + 1
          );
          const min = minTime;
          const newDate =
            new Date(new Date().toLocaleDateString()).getTime() +
            24 * 60 * 60 * 1000 -
            1;
          const max = newDate < maxTime ? newDate : maxTime;
          //如果已经选中一个日期 则 返回 该日期前后一个月时间可选
          if (this.choiceDate0) {
            return time.getTime() < min || time.getTime() > max;
          }
          //若一个日期也没选中 则 返回 当前日期以前日期可选
          return time.getTime() > newDate;
        },
      },
      // 选中数组
      ids: [],
      totalPrice: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      productOrderList: [],
      payTime: [],
      cTime: [], //搜索框 时间选择器数据
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 加单弹出层
      addOrderDialog: false,
      // 减单弹出层
      minusOrderDialog: false,
      // 查询参数
      queryParams: {
        id: "",
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        uid: null,
        pid: null,
        realName: null,
        userPhone: null,
        userAddress: null,
        productName: null,
        freightPrice: null,
        totalNum: null,
        totalPrice: null,
        totalPostage: null,
        payPrice: null,
        payPostage: null,
        deductionPrice: null,
        payTime: null,
        payType: null,
        status: null,
        shipmentStatus: null, //快递状态
        refundStatus: null,
        refundReasonTime: null,
        refundReasonWap: null,
        refundReason: null,
        refundPrice: null,
        deliveryName: null,
        deliveryType: null,
        deliveryId: null,
        isDel: null,
        cost: null,
        shippingType: null,
        channel: null,
        isSystemDel: null,
        regionalPerformance: null,
        communityPerformance: null,
        netBodyNumber: null,
      },
      // 订单状态字典
      statusOptions: [
        // 0未发货 1已发货 2已收货
        { dictValue: 0, dictLabel: "未发货" },
        { dictValue: 1, dictLabel: "待收货" },
        { dictValue: 2, dictLabel: "已收货" },
      ],
      // 表单参数
      form: {},
      deliveryForm: {
        delivery_id: "", //快递单号
        delivery_company: "", //快递公司
        status: "", //快递状态
        userPhone: "", //手机
      },
      companyOptions: [], // 快递公司简称合集
      // 表单校验
      rules: {
        uid: [{ required: true, message: "用户id不能为空", trigger: "blur" }],
        userId: [{ required: true, validator: validateID, trigger: "blur" }],
        productId: [{ required: true, validator: validateID, trigger: "blur" }],
        totalNum: [{ required: true, validator: validateID, trigger: "blur" }],
        deliveryId: [
          { required: true, message: "快递单号不能为空", trigger: "blur" },
        ],
        deliveryNumber: [
          { required: true, message: "快递公司不能为空", trigger: "blur" },
        ],
        status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
      },
      categoryOptions: [
        {
          // 分类下拉框
          value: "100",
          label: "现金",
        },
        {
          value: "200",
          label: "积分",
        },
        {
          value: "300",
          label: "事业",
        },
      ],
      payTypeOptions: [
        {
          // 支付方式下拉框
          value: "1",
          label: "支付宝",
        },
        {
          value: "2",
          label: "微信",
        },
        {
          value: "3",
          label: "余额",
        },
        {
          value: "4",
          label: "银行卡",
        },
        {
          value: "5",
          label: "系统",
        },
      ],
      addQuery: {
        // 加单 请求参数
        productId: "", //商品id
        userId: "", //用户id
        totalNum: "", //数量
      },
      chargebackQuery: {
        // 减单 请求参数
        id: "", // 订单id
        refundReasonWap: "", // 退款原因
        refundPrice: "", //退款金额
      },

      payWays: null,
    };
  },
  created() {
    this.companyOptions = delivery;
    this.getList();
    // this.getDicts("shop_order_status").then(response => {
    //   this.statusOptions = response.data;
    // });

    this.payWays = new Map();
    // [0, "微信"],
    // [1, "支付宝"],
    // [2, "银行卡"],
    // [3, "微信混合支付"],
    // [4, "支付宝混合支付"],
    // [5, "银行卡混合支付"],
    // [6, "支付宝H5"],
    // [7, "H5混合支付"],
    // [8, "微信小程序支付"],
    // [9, "微信小程序混合支付"],
    // [10, "积分店铺支付"],
    // [11, "通证店铺支付"],
    // [12, "汇付支付宝支付"],
    // [13, "汇付微信支付"]

    this.payWays.set(0, "微信");
    this.payWays.set(1, "支付宝");
    this.payWays.set(2, "银行卡支付");
    this.payWays.set(3, "微信混合支付");
    this.payWays.set(4, "支付宝混合支付");
    this.payWays.set(5, "银行卡混合支付");
    this.payWays.set(6, "支付宝H5");
    this.payWays.set(7, "H5混合支付");
    this.payWays.set(8, "微信小程序支付");
    this.payWays.set(9, "微信小程序混合支付");
    this.payWays.set(10, "积分店铺支付");
    this.payWays.set(11, "通证支付");
    this.payWays.set(12, "汇付支付宝支付");
    this.payWays.set(13, "汇付微信支付");
    // 新加
    this.payWays.set(19, "银行卡商家支付");
    this.payWays.set(20, "银联支付宝支付");
    this.payWays.set(24, "付呗支付宝支付");
    this.payWays.set(25, "付呗支付宝混合支付");
    this.payWays.set(26, "付呗商家支付");

    // this.payWays.set(20, "红包支付");
    // this.payWays.set(21, "杉德银行卡支付");
    // this.payWays.set(22, "杉德银行卡混合支付");
    // this.payWays.set(23, "炬谷支付宝支付");
    // this.payWays.set(24, "炬谷支付宝混合支付");
    // this.payWays.set(25, "炬谷支付宝线下商家支付");
    // this.payWays.set(26, "线下商家多商品红包支付");
    // this.payWays.set(27, "炬谷信用卡支付");
    // this.payWays.set(28, "银联支付宝支付");
    // this.payWays.set(29, "银联支付宝混合支付");
    // this.payWays.set(32, "付呗支付宝支付");
    // this.payWays.set(33, "付呗支付宝混合支付");
    // this.payWays.set(34, "付呗支付宝线下商家支付");
    // this.payWays.set(35, "银行卡线下商家支付");
  },
  computed: {
    /**
     * 解析订单是否已付款 发货状态
     */
    parseOrderState() {
      return (order) => {
        if (order.status === 3) {
          if (order && order.shipmentStatus === 0) {
            return "未发货";
          } else if (order && order.shipmentStatus === 1) {
            return "待收货";
          } else if (order && order.shipmentStatus === 2) {
            return "已收货";
          } else {
            return "已支付";
          }
        } else if (order.status === 4) {
          if (order && order.shipmentStatus === 0) {
            return "未发货";
          } else if (order && order.shipmentStatus === 1) {
            return "待收货";
          } else if (order && order.shipmentStatus === 2) {
            return "已收货";
          } else {
            return "已支付";
          }
        } else if (order.status === 5) {
          if (order && order.shipmentStatus === 0) {
            return "未发货";
          } else if (order && order.shipmentStatus === 1) {
            return "待收货";
          } else if (order && order.shipmentStatus === 2) {
            return "已收货";
          } else {
            return "已支付";
          }
        } else if (order.status === 6) {
          return "未支付";
        }
      };
    },

    parseOrderPayWay() {
      return (order) => {
        return this.payWays.get(order.channel);
      };
    },

    parseExpressCompony() {
      return (order) => {
        if (!order.deliveryNumber) {
          return "未发货";
        }
        let componyCode = order.deliveryNumber.toUpperCase();
        let lowerCode = order.deliveryNumber;
        let name = expressJson.reduce((initVal, item) => {
          if (item.code == componyCode) {
            initVal = item.name;
          }
          return initVal;
        }, "");
        name = delivery.reduce((initVal, item) => {
          if (item.value == lowerCode) {
            initVal = item.label;
          }
          return initVal;
        }, "");

        return name;
      };
    },
  },
  methods: {
    // 订单状态字典翻译
    // statusFormat(row, column) {
    //   return this.selectDictLabel(this.statusOptions, row.status);
    // },
    /** 查询订单列表 */
    getList() {
      this.loading = true;

      listProductOrder(
        this.addDateRange(this.queryParams, this.cTime, "")
      ).then((response) => {
        this.productOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.cTime = [];
      this.form = {
        id: null,
        orderId: null,
        uid: null,
        realName: null,
        userPhone: null,
        userAddress: null,
        pid: null,
        productName: null,
        freightPrice: null,
        totalNum: null,
        totalPrice: null,
        totalPostage: null,
        payPrice: null,
        payPostage: null,
        deductionPrice: null,
        payTime: null,
        payType: null,
        status: 0,
        refundStatus: 0,
        refundReasonTime: null,
        refundReasonWap: null,
        refundReason: null,
        refundPrice: null,
        deliveryName: null,
        deliveryType: null,
        deliveryId: null,
        isDel: null,
        cost: null,
        shippingType: null,
        channel: null,
        isSystemDel: null,
        remark: null,
        createTime: null,
        regionalPerformance: null,
        communityPerformance: null,
        netBodyNumber: null,
      };
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.totalPrice = selection.map((item) => item.totalPrice);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getProductOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 加单按钮操作 */
    addOrderClick() {
      addAchievement(this.addQuery).then((res) => {
        if (res.code === 200) {
          this.$message.success("加单成功");
        } else {
          this.$message.error("加单失败");
        }
      });
    },
    /** 减单按钮操作 */
    minusOrderDialogClick(row) {
      const id = row.id || this.ids;
      const totalPrice = this.totalPrice || 0;
      this.chargebackQuery.id = id;
      this.chargebackQuery.refundPrice = totalPrice;
      this.minusOrderDialog = true;
    },
    /** 减单确定按钮操作 */
    minusOrderClick() {
      chargeback(this.chargebackQuery).then((res) => {
        if (res.code === 200) {
          this.$message.success("减单成功");
        } else {
          this.$message.error("减单失败");
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateProductOrder(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProductOrder(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除订单编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delProductOrder(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.addDateRange(this.queryParams, this.cTime, "");
      delete queryParams.pageNum;
      delete queryParams.pageSize;
      this.$confirm("是否确认导出所有订单数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportProductOrder(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
